<template>
    <div>
        <HETTable  ref="hetTable"
            :pageSize="10"
            :tableFields="tableFields"
            :tableData="tableData"
            :enableSearch="true"
            :fields="['filename','termSpec']"
            :headerOperation="headerOperation"
            :total="total"
            @getTableData="getTableData"
        ></HETTable>
    </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { Refresh } from '@element-plus/icons-vue'
import HETTable from '~/components/common/HETTable.vue'
import {
    getGuardAppWhiteList,
    getGuardAppWhiteCount,
    getGuardAppWhiteSync
} from '~/utils/axios/defender.js'
import { useRoute } from 'vue-router'
const $route = useRoute()
const oid = $route.params.oid
const tableFields = [
  { name: "filename", label: "文件名", width:'170px'},
  { name: "termSpec", label: "文件描述", width:'160px' },
  { name: "filepath", label: "文件路径" },
  { name: "filemd5", label: "md5" }
];
const tableData = ref()
const hetTable = ref()
const total = ref(0)
const syncFn = () => {
    getGuardAppWhiteSync(oid).then(res => {
        console.log(res.data)
    }).catch(err => {
        console.log(err)
    })
}
const headerOperation = [
    {name:'同步',ev:syncFn,icon:Refresh},
]
async function getTableData(countParams, searchParams, filterName) {
    delete searchParams.$orderby;
    if(!filterName){
        searchParams.$filter = `(oid%20eq%20'${oid}')`
    }else{
        searchParams.$filter += `%20and%20(oid%20eq%20'${oid}')`
    }
    let tableDataReq = await getGuardAppWhiteList(searchParams)
    let tableCount = await getGuardAppWhiteCount({$filter:searchParams.$filter})
    tableData.value = tableDataReq.data
    total.value = tableCount.data
    hetTable.value.finish();
}
</script>

<style lang="scss" scoped>

</style>